package com.cxl.demo.mapper;

import com.cxl.demo.vo.BuyHistory;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface BuyHistoryMapper {
    @Select("select * from buyhistory where buyGoodsUserId=#{buyGoodsUserId} limit #{page},#{size}")

    @Results(value={
            @Result(property = "buyHistoryId",column = "buyHistoryId"),
            @Result(property = "goodsId",column = "goodsId"),
            @Result(property = "buyGoodsUserId",column = "buyGoodsUserId"),
            @Result(property = "buyGoodsNumber",column = "buyGoodsNumber"),
            @Result(property = "buyTime",column = "buyTime"),
            @Result(property = "logistics",column = "buyHistoryId",
                    many =@Many(select = "com.cxl.demo.mapper.LogisticsMapper.getHistoryList"))
    })


    List<BuyHistory>  findUserBuyHistory(Map<String,Object> map);
    @Select("select count(1) from buyhistory where buyGoodsUserId=#{buyGoodsUserId} ")
    Integer  findUserBuyHistoryNum(Integer buyGoodsUserId);


    @Select("select * from buyhistory where goodsId=#{goodsId} limit #{page},#{size}")

    @Results(value={
            @Result(property = "buyHistoryId",column = "buyHistoryId"),
            @Result(property = "goodsId",column = "goodsId"),
            @Result(property = "buyGoodsUserId",column = "buyGoodsUserId"),
            @Result(property = "buyGoodsNumber",column = "buyGoodsNumber"),
            @Result(property = "buyTime",column = "buyTime"),
            @Result(property = "logistics",column = "buyHistoryId",
                    many =@Many(select = "com.cxl.demo.mapper.LogisticsMapper.getHistoryList"))
    })
    List<BuyHistory> findGoodsBuyHistory(Map<String,Object> map);

    @Select("select count(1) from buyhistory where goodsId=#{goodsId}")
    Integer  findGoodsBuyHistoryNum(Integer goodsId);



    @Select("select * from buyhistory where buyHistoryId=#{buyHistoryId} ")
    BuyHistory findBuyHistoryById(Integer buyHistoryId);
    @Insert("insert into buyhistory(goodsId,buyGoodsUserId,buyGoodsNumber,buyTime) values" +
            "(#{goodsId},#{buyGoodsUserId},#{buyGoodsNumber},#{buyTime})" )
    @Options(useGeneratedKeys = true,keyProperty = "buyHistoryId",keyColumn = "buyHistoryId")
    Integer addBuyHistory(BuyHistory buyHistory);
    @Delete("delete from buyhistory where buyHistoryId=#{buyHistoryId}")
    Integer delBuyHistory(Integer buyHistoryId);
}
